from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-15 14:02:18.429278
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 15, Mar, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.5360
Nobs: 596.000 HQIC: -48.9408
Log likelihood: 7140.10 FPE: 4.29709e-22
AIC: -49.1990 Det(Omega_mle): 3.69945e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349324 0.066947 5.218 0.000
L1.Burgenland 0.107891 0.040769 2.646 0.008
L1.Kärnten -0.110654 0.021307 -5.193 0.000
L1.Niederösterreich 0.192571 0.085198 2.260 0.024
L1.Oberösterreich 0.123366 0.084044 1.468 0.142
L1.Salzburg 0.258290 0.043225 5.975 0.000
L1.Steiermark 0.036138 0.057052 0.633 0.526
L1.Tirol 0.101696 0.046068 2.208 0.027
L1.Vorarlberg -0.067933 0.040648 -1.671 0.095
L1.Wien 0.016672 0.074842 0.223 0.824
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054597 0.143943 0.379 0.704
L1.Burgenland -0.037970 0.087658 -0.433 0.665
L1.Kärnten 0.042004 0.045812 0.917 0.359
L1.Niederösterreich -0.204208 0.183186 -1.115 0.265
L1.Oberösterreich 0.455212 0.180703 2.519 0.012
L1.Salzburg 0.283374 0.092940 3.049 0.002
L1.Steiermark 0.112601 0.122669 0.918 0.359
L1.Tirol 0.305725 0.099051 3.087 0.002
L1.Vorarlberg 0.026482 0.087398 0.303 0.762
L1.Wien -0.028863 0.160918 -0.179 0.858
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198008 0.034196 5.790 0.000
L1.Burgenland 0.088702 0.020824 4.260 0.000
L1.Kärnten -0.007104 0.010883 -0.653 0.514
L1.Niederösterreich 0.241846 0.043518 5.557 0.000
L1.Oberösterreich 0.159595 0.042929 3.718 0.000
L1.Salzburg 0.040244 0.022079 1.823 0.068
L1.Steiermark 0.026691 0.029142 0.916 0.360
L1.Tirol 0.081517 0.023531 3.464 0.001
L1.Vorarlberg 0.054132 0.020762 2.607 0.009
L1.Wien 0.118541 0.038228 3.101 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118366 0.034187 3.462 0.001
L1.Burgenland 0.042959 0.020819 2.063 0.039
L1.Kärnten -0.012946 0.010881 -1.190 0.234
L1.Niederösterreich 0.172175 0.043508 3.957 0.000
L1.Oberösterreich 0.335918 0.042918 7.827 0.000
L1.Salzburg 0.099966 0.022074 4.529 0.000
L1.Steiermark 0.111231 0.029135 3.818 0.000
L1.Tirol 0.089317 0.023525 3.797 0.000
L1.Vorarlberg 0.060429 0.020758 2.911 0.004
L1.Wien -0.017653 0.038219 -0.462 0.644
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126844 0.064219 1.975 0.048
L1.Burgenland -0.044903 0.039108 -1.148 0.251
L1.Kärnten -0.045298 0.020439 -2.216 0.027
L1.Niederösterreich 0.135447 0.081728 1.657 0.097
L1.Oberösterreich 0.160262 0.080620 1.988 0.047
L1.Salzburg 0.285301 0.041465 6.881 0.000
L1.Steiermark 0.057970 0.054728 1.059 0.289
L1.Tirol 0.158216 0.044191 3.580 0.000
L1.Vorarlberg 0.097269 0.038992 2.495 0.013
L1.Wien 0.071976 0.071793 1.003 0.316
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076917 0.050112 1.535 0.125
L1.Burgenland 0.025699 0.030517 0.842 0.400
L1.Kärnten 0.053308 0.015949 3.342 0.001
L1.Niederösterreich 0.190299 0.063774 2.984 0.003
L1.Oberösterreich 0.331177 0.062909 5.264 0.000
L1.Salzburg 0.034990 0.032356 1.081 0.280
L1.Steiermark 0.007935 0.042706 0.186 0.853
L1.Tirol 0.118654 0.034483 3.441 0.001
L1.Vorarlberg 0.065701 0.030426 2.159 0.031
L1.Wien 0.097414 0.056021 1.739 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174387 0.060436 2.885 0.004
L1.Burgenland 0.004528 0.036804 0.123 0.902
L1.Kärnten -0.065797 0.019235 -3.421 0.001
L1.Niederösterreich -0.107780 0.076913 -1.401 0.161
L1.Oberösterreich 0.206716 0.075870 2.725 0.006
L1.Salzburg 0.054956 0.039022 1.408 0.159
L1.Steiermark 0.246691 0.051504 4.790 0.000
L1.Tirol 0.500766 0.041588 12.041 0.000
L1.Vorarlberg 0.064200 0.036695 1.750 0.080
L1.Wien -0.075638 0.067563 -1.120 0.263
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160812 0.067031 2.399 0.016
L1.Burgenland -0.002123 0.040820 -0.052 0.959
L1.Kärnten 0.062960 0.021333 2.951 0.003
L1.Niederösterreich 0.166568 0.085305 1.953 0.051
L1.Oberösterreich -0.056276 0.084149 -0.669 0.504
L1.Salzburg 0.208567 0.043280 4.819 0.000
L1.Steiermark 0.138500 0.057124 2.425 0.015
L1.Tirol 0.055633 0.046126 1.206 0.228
L1.Vorarlberg 0.146936 0.040699 3.610 0.000
L1.Wien 0.121642 0.074936 1.623 0.105
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389909 0.039409 9.894 0.000
L1.Burgenland -0.003314 0.023999 -0.138 0.890
L1.Kärnten -0.020842 0.012543 -1.662 0.097
L1.Niederösterreich 0.203006 0.050153 4.048 0.000
L1.Oberösterreich 0.228514 0.049474 4.619 0.000
L1.Salzburg 0.037056 0.025445 1.456 0.145
L1.Steiermark -0.015794 0.033585 -0.470 0.638
L1.Tirol 0.089527 0.027119 3.301 0.001
L1.Vorarlberg 0.050901 0.023928 2.127 0.033
L1.Wien 0.043942 0.044057 0.997 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036644 0.104642 0.167771 0.138162 0.096482 0.080319 0.032274 0.209872
Kärnten 0.036644 1.000000 -0.027204 0.131207 0.048636 0.084697 0.443763 -0.067160 0.089319
Niederösterreich 0.104642 -0.027204 1.000000 0.312215 0.119132 0.271953 0.065896 0.152259 0.290873
Oberösterreich 0.167771 0.131207 0.312215 1.000000 0.212293 0.294840 0.166397 0.136360 0.237742
Salzburg 0.138162 0.048636 0.119132 0.212293 1.000000 0.122341 0.091743 0.104782 0.123808
Steiermark 0.096482 0.084697 0.271953 0.294840 0.122341 1.000000 0.133185 0.106257 0.035183
Tirol 0.080319 0.443763 0.065896 0.166397 0.091743 0.133185 1.000000 0.063323 0.150847
Vorarlberg 0.032274 -0.067160 0.152259 0.136360 0.104782 0.106257 0.063323 1.000000 -0.004535
Wien 0.209872 0.089319 0.290873 0.237742 0.123808 0.035183 0.150847 -0.004535 1.000000